Skip to main content

Sugar - Five-way Rocker

Introduction

This is a five-way joystick, which can detect the values of the four directions of the X and Y horizontal axes and the vertical axis press. It is a relatively special I2C module. image.png

Parameters


Dimension24 x 24 x 23 mm
Weight7 g
TypeI2C
RangeX: -255~255
Y: -255~255
Z: Pressed or not

 Circuit Connection


Connect the joystick module to the Robotbit Edu's blue I2C interface using a 4PIN terminal wire. Turn on the Robotbit power supply to see the red light at the bottom of the photosensitive module light up (the module is normally powered) joystick.png

Coding


Using Kittenblock

You can concatenate strings (numbers will be converted to strings) using the Join block under the Operation block category.

info

Due to poor online interaction real-time performance, it is recommended to upload the program and run it on the Future board. If you are not sure how to upload offline, please refer to Quick Start

image-20240315120519886

image-20240315120734074

danger

Note that the colon in the English character string block should be an English colon (please do not enter the Chinese input method)

Joystick Direction Value

value(dir)

  • dir: Select direction
    • 'x': X axis, return value range -255~255
    • 'y': Y axis, return value range -255~255 state()
  • Return value:
    • Default state: 'none'
    • Other states: Detect 5-way state, according to the trigger state can return "pressed", "left", "right", "up" or "down".
from future import *
from sugar import *
joystick = Joystick()
screen.sync = 0
while True:
screen.fill((0, 0, 0))
screen.text(str("X: ")+str(joystick.value('x')), x = 5, y = 10)
screen.text(str("Y: ")+str(joystick.value('y')), x = 5, y = 30)
if joystick.state() == 'pressed':
screen.text("Pressed", x = 5, y = 50)
screen.refresh()

Effect Display

Print the data of the X and Y axes on the Future Board screen. When the joystick is pressed, the third line of the screen will display Pressed joystick.mp4

Using on Microbit

Robotbit_压缩后.png

Programming platform

Microsoft MakeCode for micro:bit Use Makecode programming platform

Add Sugar Plugin

image-20240311154521941image.png Search for Sugar in the extensions, click Add

Building Blocks-Function Description

Sr. No.Building Block ImageBuilding Block Function
1image-20240315120937472Read Joystick Status
2image-20240315120957085Read Joystick Raw Value

Circuit Connection

image.png

Microbit InterfaceCable
Five-way joystick.pngSugar cube joystick moduleI2CBlack PH2.0-4Pin interface cablePH2.0-4pin.png

Case: Control display

image-20240315121915870